#pragma once
#include <QWidget>
#include <QPlainTextEdit>
#include <QLineEdit>
#include <QVBoxLayout>
#include <QCompleter>
#include <QStringListModel>

/**
 * 内置控制台窗口：
 *  - 上方 QPlainTextEdit 显示输出
 *  - 下方 QLineEdit 输入命令，支持历史与自动补全
 */
class ConsoleWidget : public QWidget
{
    Q_OBJECT
public:
    explicit ConsoleWidget(QWidget *parent = nullptr);

    // 设置命令自动补全词表
    void setCommandList(const QStringList &cmds);

signals:
    void commandEntered(const QString &cmd);

public slots:
    void appendOutput(const QString &text);

protected:
    void keyPressEvent(QKeyEvent *event) override;

private slots:
    void onReturnPressed();

private:
    QPlainTextEdit *output = nullptr;
    QLineEdit *input = nullptr;

    // 历史命令
    QStringList history;
    int historyIndex = -1;

    // 自动补全
    QCompleter *completer = nullptr;
    QStringListModel *cmdModel = nullptr;
};
